define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {

		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_comments(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"total":100,"discuss_info":[{"author":"张三","time":"2017/01/11 18:50:02","score":[{"name":"描述相符","point":2},{"name":"服务态度","point":3},{"name":"发货速度","point":5}],"comment":"好评吧，挺愉快的一次网购，还没开始用，过几天再追评。好评吧，挺愉快的一次网购，还没开始用，过几天再追评。好评吧，挺愉快的一次网购，还没开始用，过几天再追评过几天再追评过几天再追评我","items":[{"author":"游客1","time":"2017/01/02 15:20:00","comment":"我前几天也买了，也觉得不错","id":1},{"author":"游客2","time":"2017/01/02 11:00:20","comment":"我倒倒霉了，拿到手的货和网页上的描写相差好大，晕死","id":2}]},{"author":"李四","time":"2017/01/02 19:10:00","score":[{"name":"描述相符","point":4},{"name":"服务态度","point":4},{"name":"发货速度","point":4}],"comment":"非常愉快的一次网购，下次再来","items":[{"author":"游客1","time":"2017/01/02 09:00:00","comment":"质量一般般吧","id":1},{"author":"游客2","time":"2017/01/02 09:00:00","comment":"我下次不来了，没钱了","id":2}],"id":1}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		
		//返回信息
		return {
			//图文详情
			get_description:function(goods_id,callbcak){
				Http.post({
					method:'goods.get_description',
					goods_id:goods_id
				},function(result){
					if(callbcak)
						callbcak(result.result);
				})
			},
			//商品评价
			get_comments: function(goods_id,filter,nPage,callback,calldone) {
				Http.post({
					method: 'goods.get_discuss',
					goods_id: goods_id,
					filter: filter,
					pagelimit: 10,
					nPage: nPage
				},
				function(result) {
					if(callback)
						callback(get_comments(result).result);
				},
				function(e) {
					//请求异常
				},
				function() {
					if(calldone)
						calldone();
				});
			},
			//商品问答
			get_consults:function(goods_id,nPage,callback,calldone){
				Http.post({
					method:'goods.get_consults',
					goods_id:goods_id,
					nPage:nPage
				},function(result){
					if(callback)
						callback(result.result);
				},function(e){
					
				},function(){
					if(calldone)
						calldone();
				})
			},
			//销售记录
			get_log: function(goods_id, nPage, callbcak, calldone) {
				Http.post({
					method: 'goods.get_selllog',
					goods_id: goods_id,
					nPage: nPage,
					pagelimit: 20
				}, function(result) {
					if(callbcak)
						callbcak(result.result);
				},
				function(e) {
					//请求异常
				},
				function() {
					if(calldone)
						calldone();
				})
			},
			ask:function(goods_id,comment,hidden_name,callback){
				Http.post({
					method:'goods.post_ask',
					goods_id:goods_id,
					comment:comment,
					hidden_name:hidden_name
				},function(result){
					if(callback){
						callback(result)
					}
				})
			}
		
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Product_info", factory);
});